package com.taotao.manage.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.taotao.manage.pojo.ItemCat;
import com.taotao.manage.service.ItemCatService;

/**
 * 商品分类模块
 * @author Beck
 *
 */
@RequestMapping("item/cat")
@Controller
public class ItemCatController {
	@Autowired
	private ItemCatService itemCatService;

	/**
	 * 根据父类的id，获取所有的子分类
	 */
	@RequestMapping(value="all", method=RequestMethod.GET)
	public ResponseEntity<List<ItemCat>> getItemCatByParentId(@RequestParam(value="id", defaultValue="0") Long parentId){
		try {
			ItemCat record = new ItemCat();
			record.setParentId(parentId);
			record.setStatus(1);
			List<ItemCat> list = this.itemCatService.queryListByWhere(record );
			// 查询成功，返回200
			return ResponseEntity.status(HttpStatus.OK).body(list);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// 返回500
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
}
